import { http } from '@/lib/request'
import type { queryPagination } from '../types'

interface CreateAudioData {
  graphic_creation_no: string // 图形创建编号
  officalAccountOrientation: string // 官方账号定位
  pictureType: number // 图片类型
  pictureStyle: number // 图片风格
  keywords: string // 关键词
}

export interface AudioResponse {
  id: number
  user_id: number
  graphic_creation_id: string
  status: string
  officalAccountOrientation: string
  pictureType: number
  pictureStyle: number
  keywords: string
  result: {
    msg: string
    data: any
  }
  updated_at: string
  created_at: string
  graphic_creation: {
    user_id: number
    no: string
    type: string
    updated_at: string
    created_at: string
    id: number
  }
}

export const audioService = {
  // 创建图文任务
  graphicCreationStore: async (data: CreateAudioData) => {
    return http.post<AudioResponse>('/graphicCreation/officalAccount/store', data)
  },
  // 图文任务详情
  graphicCreationDetail: async (id: string) => {
    return http.get<{
      status: string
      result: {
        msg: string
        data: any
      }
      graphic_creation_offical_account_pictures: { id: string }[]
      graphic_creation_offical_account_texts: { id: string }[]
    }>(`/graphicCreation/officalAccount/detail?id=${id}`)
  },

  // 图片任务详情
  graphicPictureDetail: async (id: string) => {
    return http.get<{
      status: string
      result: {
        msg: string
        data: any[]
      }
    }>(`/graphicCreation/officalAccount/picture/pictureDetail?id=${id}`)
  },
  // 文案任务详情
  graphicTextDetail: async (id: string) => {
    return http.get<{
      status: string
      result: {
        msg: string
        data: string
      }
    }>(`/graphicCreation/officalAccount/text/textDetail?id=${id}`)
  },
  // 重新生成文案任务
  graphicTextDetailReload: async (id: string) => {
    return http.get<{
      status: string
      result: {
        msg: string
        data: string
      }
    }>(`/graphicCreation/officalAccount/text/reload?id=${id}`)
  },
  // 图片任务重新生成其中一张图片
  reloadPicture: async (data: { id: string; picture_id: string }) => {
    return http.get<{
      status: string
      result: {
        msg: string
        data: string
      }
    }>('/graphicCreation/officalAccount/picture/reloadPicture', {
      params: data,
    })
  },
  // 图文任务列表
  graphicCreationList: async ({
    no,
    status,
  }: {
    no: string
    status: string // 状态，多个以引文逗号拼接
  }) => {
    return http.get<any>('/graphicCreation/officalAccount/list', {
      params: {
        no,
        status,
      },
    })
  },
  // 图文任务列表 for History
  graphicCreationListForHistory: async (params: queryPagination) => {
    return http.get<any>('/graphicCreation/officalAccount/list', {
      params: {
        ...params,
        status: 'finish',
      },
    })
  },
  // 文案任务列表
  graphicTextList: async (
    params: {
      graphic_creation_offical_account_id?: string
    } & queryPagination,
  ) => {
    return http.get<any>('/graphicCreation/officalAccount/text/textList', {
      params,
    })
  },
}
